package com.diandian.backend.kuaishou.life.exchange.controller;

import com.diandian.backend.kuaishou.life.exchange.service.BusinessTokenGetService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.kuaishou.life.boot.starter.dto.StoreCategoryRespDTO;
import com.diandian.kuaishou.life.boot.starter.service.KuaiShouLifeStoreBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/store")
public class StoreController {

    @Autowired
    private KuaiShouLifeStoreBasicService kuaiShouLifeStoreBasicService;

    @Autowired
    private BusinessTokenGetService businessTokenGetService;

    /**
     * 商家门店信息批量查询（分页）
     */
    @GetMapping( "/getPage")
    public BaseResult getStorePage(@RequestHeader(name = "appKey") String appKey,
                              @RequestHeader(name = "appSecret") String appSecret,
                              @RequestHeader(value = "merchantId") String merchantId,
                              @RequestParam(value = "cursor") String cursor,
                              @RequestParam(value = "limit") Integer limit) {
        String accessToken = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        return new BaseResult(0, "success", kuaiShouLifeStoreBasicService.getStorePage(accessToken, cursor, limit));
    }

    /**
     * 商家门店信息批量查询（全部）
     */
    @GetMapping( "/getAll")
    public BaseResult getAll(@RequestHeader(name = "appKey") String appKey,
                              @RequestHeader(name = "appSecret") String appSecret,
                              @RequestHeader(value = "merchantId") String merchantId) {
        String accessToken = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        return new BaseResult(0, "success", kuaiShouLifeStoreBasicService.getAllStore(accessToken));
    }

    /**
     * 查询商家类目
     */
    @GetMapping( "/category")
    public BaseResult getProductCategory(@RequestHeader(name = "appKey") String appKey,
                                         @RequestHeader(name = "appSecret") String appSecret,
                                         @RequestHeader(name = "merchantId", required = false) String merchantId,
                                         @RequestParam(name = "categoryId", required = false) String categoryId) {
        String token = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        StoreCategoryRespDTO categoryRespDTO = kuaiShouLifeStoreBasicService.getStoreCategory(categoryId, token);
        return new BaseResult(0, "success", categoryRespDTO);
    }

    /**
     * 门店信息查询接口（分页）
     */
    @GetMapping( "/info/page")
    public BaseResult getStoreInfoPage(@RequestHeader(name = "appKey") String appKey,
                                         @RequestHeader(name = "appSecret") String appSecret,
                                         @RequestHeader(name = "merchantId", required = false) String merchantId,
                                         @RequestParam(name = "page") Integer page,
                                         @RequestParam(name = "size") Integer size,
                                         @RequestParam(name = "thirdId", required = false) Long thirdId,
                                         @RequestParam(name = "accountId", required = false) Long accountId,
                                         @RequestParam(name = "poiId", required = false) Long poiId) {
        String token = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        return new BaseResult(0, "success", kuaiShouLifeStoreBasicService.getStoreInfoPage(token, page, size, thirdId, accountId, poiId));
    }

    /**
     * 门店信息查询接口（全部）
     */
    @GetMapping( "/info/all")
    public BaseResult getAllStoreInfo(@RequestHeader(name = "appKey") String appKey,
                                         @RequestHeader(name = "appSecret") String appSecret,
                                         @RequestHeader(name = "merchantId", required = false) String merchantId,
                                         @RequestParam(name = "thirdId", required = false) Long thirdId,
                                         @RequestParam(name = "accountId", required = false) Long accountId,
                                         @RequestParam(name = "poiId", required = false) Long poiId) {
        String token = businessTokenGetService.getToken(appKey, appSecret, merchantId);
        return new BaseResult(0, "success", kuaiShouLifeStoreBasicService.getAllStoreInfo(token, thirdId, accountId, poiId));
    }

}
